enum BOX{
    //%block="x coordinate"
    x,
    //%block="y coordinate"
    y,
    //%block="square frame width"
    w,
    //%block="square frame height"
    h,
    //%block="news"
    msg

}
enum K210_FUNCTION_ENUM{
    //%block="facial recognition"
    ai_face_recognition,
    //%block="qr code recognition"
    ai_or_code_recognition,
    //%block="shopsavvy barcode scanner"
    ai_barcode_recognition ,
    //%block="mask detection"
    ai_findFacemaskFollow,
    //%block="object recognition"
    ai_findObjectFollow,
    //%block="roadsign tracking"
    ai_findSignpostFoll,
    //%block="digital card recognition"
    ai_findDigitalCard,
    //%block="garbage classification recognition"
    ai_garbageSorting ,
    //%block="multiple color recognition"
    ai_findMultiColor,
    //%block="license plate recognition"
    ai_licenseplate,
    //%block="autonomous learning classification"
    ai_find_self_learning


}
enum UART{
    //%block="Hard serial port 1"
    Serial1,
    //%block="Hard serial port 2"
    Serial2,
    //%block="Soft serial port"
    SoftSerial
}
enum LED{
    //%block="close"
    0,
    //%block="open"
    1,
}
enum FILL{
    //%block="fill in light"
    FILL_IN_LIGHT,
    //%block="screen backlight"
    BACKLIGHT,
}

//% color="#33CCFF" iconWidth=50 iconHeight=40
namespace K210{

      //% block="initialize the k 210 visual module[UART]RX[RX]TX[TX]baudRate9600" blockType="command"
      //% RX.shadow="dropdown" TX.shadow="dropdown" TX.options="PIN_TX" RX.options="PIN_RX"
      //% UART.shadow="dropdown" UART.options="UART" UART.defl="UART.1"
      export function begin(parameter: any, block: any) {
        let rx = parameter.RX.code
        let tx = parameter.TX.code
        let uart = parameter.UART.code
        Generator.addInclude('XYXKC_K210Include', '#include <XYXKC_K210.h>');
          Generator.addObject('XYXKC_K210bject', 'XYXKC_K210',`xyxkc_K210;`);
          if (uart == "SoftSerial"){
              Generator.addInclude('SoftwareSerialInclude', '#include <SoftwareSerial.h>');
              Generator.addObject('SoftwareSerialbject', 'SoftwareSerial',`SoftSerial(${rx}, ${tx});`);
              Generator.addSetup(`XYXKC_K210Setup`,`xyxkc_K210.begin(&SoftSerial);`)
          }else{
              Generator.addSetup(`XYXKC_K210Setup`,`xyxkc_K210.begin(&${uart},${rx}, ${tx});`)
          }


      }
    //% block="switch the k 210 visual module to[FUN]algorithm until successful" blockType="command"
    //% FUN.shadow="dropdown" FUN.options="K210_FUNCTION_ENUM" FUN.defl="K210_FUNCTION_ENUM.ai_face_recognition"
    export function algorithmSwitching(parameter: any, block: any) {
        let fun = parameter.FUN.code
        Generator.addCode(`xyxkc_K210.algorithmSwitching(${fun});`)
    }

    //% block="k 210 vision module obtains data once" blockType="command"
    export function retrieveDataOnce(parameter: any, block: any) {
        Generator.addCode(`xyxkc_K210.retrieveDataOnce();`)
    }

    //% block="analysis of k 210 visual module[FUN]data" blockType="command"
    //% FUN.shadow="dropdown" FUN.options="K210_FUNCTION_ENUM" FUN.defl="K210_FUNCTION_ENUM.ai_face_recognition"
    export function parsingData(parameter: any, block: any) {
        let fun = parameter.FUN.code
        Generator.addObject(`${fun}_msg_data_Objct`, 'K210FunMSG',`${fun}_msg_data;`);
        Generator.addCode(`bool ${fun}_msg_data_bool = xyxkc_K210.parsingData(${fun},${fun}_msg_data);`)
    }
    //% block="analysis of k 210 visual module[FUN]data success？" blockType="boolean"
    //% FUN.shadow="dropdown" FUN.options="K210_FUNCTION_ENUM" FUN.defl="K210_FUNCTION_ENUM.ai_face_recognition"
    export function isparsingData(parameter: any, block: any) {
        let fun = parameter.FUN.code
        Generator.addCode(`(${fun}_msg_data_bool)`)
    }
    //% block="k 210 visual module acquisition[FUN]the data[BOX]" blockType="reporter"
    //% FUN.shadow="dropdown" FUN.options="K210_FUNCTION_ENUM" FUN.defl="K210_FUNCTION_ENUM.ai_face_recognition"
    //% BOX.shadow="dropdown" BOX.options="BOX" BOX.defl="BOX.x"
    export function getparsingData(parameter: any, block: any) {
        let fun = parameter.FUN.code
        let box = parameter.BOX.code
        Generator.addCode(`(${fun}_msg_data.${box})`)
    }
    //% block="[LED]k 210 visual module[FILL]" blockType="command"
    //% FILL.shadow="dropdown" FILL.options="FILL" FILL.defl="FILL.FILL_IN_LIGHT"
    //% LED.shadow="dropdown" LED.options="LED" LED.defl="LED.0"
    export function fillInLight(parameter: any, block: any) {
        let led = parameter.LED.code
        let fill = parameter.FILL.code
        Generator.addCode(`xyxkc_K210.fillInLight(${fill},${led});`)
    }
    //% block="Take a photo of the K 210 visual module and save it to the SD card" blockType="command"
    export function saveImage(parameter: any, block: any) {
        Generator.addCode(`xyxkc_K210.saveImage();`)
    }
    //% block="Take a photo with the K 210 visual module and convert it to base 64 encoding until successful" blockType="command"
    export function getImageBase64(parameter: any, block: any) {
        Generator.addCode(`xyxkc_K210.getImageBase64();`)
    }
    //% block="K 210 visual module obtains photos with base 64 encoding" blockType="reporter"
    export function getBase64(parameter: any, block: any) {
        Generator.addCode(`xyxkc_K210.getBase64()`)
    }
}